home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / GDIOBJEC.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  45KB  |  1,752 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.16  $
  6. //
  7. // Definition of abstract GDI object class and derived classes
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_GDIOBJEC_H)
  10. #define OWL_GDIOBJEC_H
  11.  
  12. #if !defined(OWL_GDIBASE_H)
  13. # include <owl/gdibase.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace ClassLib {
  18. #endif
  19.   
  20. class _BIDSCLASS TFile;
  21.  
  22. #if defined(BI_NAMESPACE)
  23. } // namespace ClassLib
  24. #endif
  25.  
  26.  
  27. #if defined(BI_NAMESPACE)
  28. namespace OWL {
  29. #endif
  30.  
  31. class _OWLCLASS TDC;
  32. class _OWLCLASS TBrush;
  33. class _OWLCLASS TBitmap;
  34. class _OWLCLASS TDib;
  35. class _OWLCLASS TPalette;
  36. class _OWLCLASS TClipboard;
  37. class _OWLCLASS TMetaFilePict;
  38.  
  39. //
  40. // Define to not share handles in copy ctors, otherwise these classes may act
  41. // as envelopes and treat the handles as ref counted letters
  42. //
  43. //#define NO_GDI_SHARE_HANDLES
  44.  
  45. //
  46. // GDI Orphan control element
  47. //
  48. struct TObjInfo;
  49.  
  50. // Generic definitions/compiler options (eg. alignment) preceeding the 
  51. // definition of classes
  52. #include <services/preclass.h>
  53.  
  54. //
  55. // class TGdiObject
  56. // ~~~~~ ~~~~~~~~~~
  57. // Abstract base class for Windows GDI objects. Provides base, destruction &
  58. // orphan control for true GDI objects
  59. //
  60. class _OWLCLASS TGdiObject : private TGdiBase {
  61.   public:
  62.     // Class scoped types
  63.     //
  64.     typedef HGDIOBJ THandle;  // TGdiObject encapsulates an HGDIOBJ
  65.  
  66.     // Destructor
  67.     //
  68.    ~TGdiObject();  // GDI classes are not polymorphic, & dtor is not virtual
  69.  
  70.     HGDIOBJ     GetGdiHandle() const;
  71.     operator    HGDIOBJ() const;
  72.  
  73.     int         GetObject(int count, void far* object) const;
  74.     bool        operator ==(const TGdiObject& other) const;
  75.  
  76.     bool        IsGDIObject() const;
  77. #if defined(BI_PLAT_WIN32)
  78.     uint32      GetObjectType() const;
  79. #endif
  80.  
  81.     // GDI handle management & orphan control
  82.     //
  83.     enum TType {
  84.       None, Pen, Brush, Font, Palette, Bitmap, TextBrush
  85.     };
  86.  
  87.     static TObjInfo* RefFind(HANDLE object);
  88.     static void      RefAdd(HANDLE handle, TType type);
  89.     static void      RefRemove(HANDLE handle);
  90.     static void      RefInc(HANDLE handle);
  91.     static void      RefDec(HANDLE handle, bool wantDelete);
  92.     static int       RefCount(HANDLE handle);
  93.  
  94.   protected:
  95.     TGdiBase::CheckValid;  // make this function available to derivatives
  96.     TGdiBase::Handle;      // and these members too
  97.     TGdiBase::ShouldDelete;
  98.  
  99.     // Constructors for use by derived classes only
  100.     //
  101.     TGdiObject();
  102.     TGdiObject(HANDLE handle, TAutoDelete autoDelete = NoAutoDelete);
  103.  
  104.   private:
  105.     TGdiObject(const TGdiObject&); // Protect against copying of GDI objects
  106.     TGdiObject& operator =(const TGdiObject&);
  107.  
  108. #if defined(OWL2_COMPAT)
  109.   public:
  110.     typedef ::TXGdi TXGdi;  // Exceptions moved to global scope
  111. #endif
  112. };
  113.  
  114. //
  115. // class TPen
  116. // ~~~~~ ~~~~
  117. // GDI Pen class. Can construct a pen from explicit info, or indirectly
  118. //
  119. class _OWLCLASS TPen : public TGdiObject {
  120.   public:
  121.     // Class scoped types
  122.     //
  123.     typedef HPEN THandle;  // TPen encapsulates an HPEN
  124.  
  125.     // Constructors
  126.     //
  127.     TPen(HPEN handle, TAutoDelete autoDelete = NoAutoDelete);
  128.  
  129.     TPen(const TColor& color, int width=1, int style=PS_SOLID);
  130.     TPen(const LOGPEN far* logPen);
  131.     TPen(const TPen& src);
  132. #if defined(BI_PLAT_WIN32)
  133.     TPen(uint32 penStyle, uint32 width, const TBrush& brush, uint32 styleCount,
  134.          uint32* style);
  135.     TPen(uint32 penStyle, uint32 width, const LOGBRUSH& logBrush,
  136.          uint32 styleCount, uint32* style);
  137. #endif
  138.  
  139.     // Type Accessor & Conversion Operator
  140.     //
  141.     HPEN     GetHandle() const;
  142.     operator HPEN() const;
  143.  
  144.     // Get GDI Pen Object information
  145.     //
  146.     bool        GetObject(LOGPEN far& logPen) const;
  147.  
  148.   private:
  149.     TPen& operator =(const TPen&);
  150. };
  151.  
  152. //
  153. // class TBrush
  154. // ~~~~~ ~~~~~~
  155. // GDI Brush class. Can construct a brush from explicit info, creating a
  156. // solid, styled, or patterned brush.  Can also create a brush indirectly.
  157. //
  158. class _OWLCLASS TBrush : public TGdiObject {
  159.   public:
  160.     // Class scoped types
  161.     //
  162.     typedef HBRUSH THandle;  // TBrush encapsulates an HBRUSH
  163.  
  164.     // Constructors
  165.     //
  166.     TBrush(HBRUSH handle, TAutoDelete autoDelete = NoAutoDelete);
  167.  
  168.     TBrush(const TColor& color);
  169.     TBrush(const TColor& color, int style);
  170.     TBrush(const TBitmap& pattern);
  171.     TBrush(const TDib& pattern);
  172.     TBrush(const LOGBRUSH far* logBrush);
  173.     TBrush(const TBrush& src);
  174.    ~TBrush();
  175.  
  176.     // Type Accessor & Conversion Operator
  177.     //
  178.     HBRUSH   GetHandle() const;
  179.     operator HBRUSH() const;
  180.  
  181.     // Get GDI Brush Object information
  182.     //
  183.     bool        GetObject(LOGBRUSH far& logBrush) const;
  184. #if defined(BI_PLAT_WIN16)
  185.     bool        UnrealizeObject();  // Use TDC::SetBrushOrg() for Win32
  186. #endif
  187.  
  188.   private:
  189.     TBrush& operator =(const TBrush&);
  190. };
  191.  
  192. //
  193. // class THatch8x8Brush
  194. // ~~~~~ ~~~~~~~~~~~~~~
  195. // Mini 8x8 monochrome configurable hatch brush class, with predefined patterns
  196. //
  197. class _OWLCLASS THatch8x8Brush : public TBrush {
  198.   public:
  199.     THatch8x8Brush(const uint8 hatch[], const TColor& fgColor=TColor::White,
  200.                    const TColor& bgColor=TColor::Black);
  201.     void     Reconstruct(const uint8 hatch[], const TColor& fgColor, const TColor& bgColor);
  202.  
  203.     const static uint8 Hatch22F1[8];  // 2-on, 2-off, offset 1 per row forward
  204.     const static uint8 Hatch13F1[8];  // 1-on, 3-off, offset 1 per row forward
  205.     const static uint8 Hatch11F1[8];  // 1-on, 1-off, offset 1 per row
  206.     const static uint8 Hatch22B1[8];  // 2-on, 2-off, offset 1 per row backward
  207.     const static uint8 Hatch13B1[8];  // 1-on, 3-off, offset 1 per row backward
  208.  
  209.   private:
  210.     static HBRUSH Create(const uint8 hatch[], const TColor& fgColor, const TColor& bgColor);
  211. };
  212.  
  213. //
  214. // class TFont
  215. // ~~~~~ ~~~~~
  216. // GDI Font class.  Can construct a font from explicit info, or indirectly.
  217. //
  218. class _OWLCLASS TFont : public TGdiObject {
  219.   public:
  220.     // Class scoped types
  221.     //
  222.     typedef HFONT THandle;  // TFont encapsulates an HFONT
  223.  
  224.     // Constructors
  225.     //
  226.     TFont(HFONT handle, TAutoDelete autoDelete = NoAutoDelete);
  227.  
  228.     // Convenient font ctor
  229.     //
  230.     TFont(const char far* facename=0,
  231.           int height=0, int width=0, int escapement=0, int orientation=0,
  232.           int weight=FW_NORMAL,
  233.           uint8 pitchAndFamily=DEFAULT_PITCH|FF_DONTCARE,
  234.           uint8 italic=false, uint8 underline=false, uint8 strikeout=false,
  235.           uint8 charSet=1,  // DEFAULT_CHARSET or UNICODE_CHARSET
  236.           uint8 outputPrecision=OUT_DEFAULT_PRECIS,
  237.           uint8 clipPrecision=CLIP_DEFAULT_PRECIS,
  238.           uint8 quality=DEFAULT_QUALITY);
  239.  
  240.     // CreateFont() matching font ctor
  241.     //
  242.     TFont(int height, int width, int escapement=0, int orientation=0,
  243.           int weight=FW_NORMAL,
  244.           uint8 italic=false, uint8 underline=false, uint8 strikeout=false,
  245.           uint8 charSet=1,  // DEFAULT_CHARSET or UNICODE_CHARSET
  246.           uint8 outputPrecision=OUT_DEFAULT_PRECIS,
  247.           uint8 clipPrecision=CLIP_DEFAULT_PRECIS,
  248.           uint8 quality=DEFAULT_QUALITY,
  249.           uint8 pitchAndFamily=DEFAULT_PITCH|FF_DONTCARE,
  250.           const char far* facename=0);
  251.     TFont(const LOGFONT far* logFont);
  252.     TFont(const TFont& src);
  253.  
  254.     // Type Accessor & Conversion Operator
  255.     //
  256.     HFONT       GetHandle() const;
  257.     operator    HFONT() const;
  258.  
  259.     // Retrieve info about this font when selected in the specified dc
  260.     //
  261.     TEXTMETRIC  GetTextMetrics(TDC& dc) const;
  262.     void        GetTextMetrics(TEXTMETRIC& tm, TDC& dc) const;
  263.  
  264.     // Retrieve info about this font when selected in a screen DC
  265.     //
  266.     TEXTMETRIC  GetTextMetrics() const;
  267.     void        GetTextMetrics(TEXTMETRIC& tm) const;
  268.  
  269.     // Retrieve specific attribute of font
  270.     //
  271.     int         GetHeight() const;
  272.     int         GetHeight(TDC& dc) const;
  273.     int         GetAveWidth() const;
  274.     int         GetAveWidth(TDC& dc) const;
  275.     int         GetMaxWidth() const;
  276.     int         GetMaxWidth(TDC& dc) const;
  277.     TSize       GetTextExtent(const char far* text) const;
  278.     TSize       GetTextExtent(TDC& dc, const char far* text) const;
  279.  
  280.     // Retrieve attributes of logical font
  281.     //
  282.     bool            GetObject(LOGFONT far& logFont) const;
  283.     const string&   GetFaceName() const;
  284.     uint8           GetPitchAndFamily() const;
  285.  
  286.   private:
  287.     TFont& operator =(const TFont&);
  288. };
  289.  
  290. //
  291. // class TDefaultGUIFont
  292. // ~~~~~ ~~~~~~~~~~~~~~~
  293. // Default GUI font classe encapsulating font used for user interface objects
  294. // such as menus and dialog boxes.
  295. //
  296. class _OWLCLASS TDefaultGUIFont : public TFont {
  297.   public:
  298.     TDefaultGUIFont();
  299. };
  300.  
  301. //
  302. // class TPalette
  303. // ~~~~~ ~~~~~~~~
  304. // GDI Palette class.  Can construct a palette from explicit info, or
  305. // indirectly from various color table types that are used by DIBs.
  306. //
  307. class _OWLCLASS TPalette : public TGdiObject {
  308.   public:
  309.     // Class scoped types
  310.     //
  311.     typedef HPALETTE THandle;  // TPalette encapsulates an HPALETTE
  312.  
  313.     // Constructors
  314.     //
  315.     TPalette(HPALETTE handle, TAutoDelete autoDelete = NoAutoDelete);
  316.  
  317.     TPalette(const TClipboard&);
  318.     TPalette(const TPalette& src);          // Deep copy whole palette
  319.  
  320.     TPalette(const LOGPALETTE far* logPalette);
  321.     TPalette(const PALETTEENTRY far* entries, int count);
  322.     TPalette(const BITMAPINFO far* info, uint flags=0);    //Win 3.0 DIB hdr
  323.     TPalette(const TDib& dib, uint flags=0);               // DIB object
  324.  
  325.     // Type Accessor & Conversion Operator
  326.     //
  327.     HPALETTE GetHandle() const;
  328.     operator HPALETTE() const;
  329.  
  330.     // Palette functions
  331.     //
  332.     bool        ResizePalette(uint numEntries);
  333.     void        AnimatePalette(uint start, uint count, const PALETTEENTRY far* entries);
  334.     uint        SetPaletteEntries(uint16 start, uint16 count, const PALETTEENTRY far* entries);
  335.     uint        SetPaletteEntry(uint16 index, const PALETTEENTRY far& entry);
  336.     uint        GetPaletteEntries(uint16 start, uint16 count, PALETTEENTRY far* entries) const;
  337.     uint        GetPaletteEntry(uint16 index, PALETTEENTRY far& entry) const;
  338.     uint        GetNearestPaletteIndex(const TColor& color) const;
  339.     bool        GetObject(uint16 far& numEntries) const;
  340.     uint16      GetNumEntries() const;
  341.  
  342.     // Put this palette onto the clipboard
  343.     //
  344.     void        ToClipboard(TClipboard& Clipboard);
  345.     bool        UnrealizeObject();
  346.  
  347.   protected:
  348.     void        Create(const BITMAPINFO far* info, uint flags);
  349.  
  350.   private:
  351.     TPalette& operator =(const TPalette&);
  352.  
  353. #if defined(OWL2_COMPAT)
  354.   public:
  355.     TPalette(const BITMAPCOREINFO far* core, uint flags=0);//PM 1.0 DIB header
  356.   protected:
  357.     void        Create(const BITMAPCOREINFO far* core, uint flags);
  358. #endif
  359. };
  360.  
  361. //
  362. // class TBitmap
  363. // ~~~~~ ~~~~~~~
  364. // GDI Bitmap class.  Can construct a bitmap from many sources.  This bitmap
  365. // is the lowest level object that is actually selected into a DC.
  366. //
  367. class _OWLCLASS TBitmap : public TGdiObject {
  368.   public:
  369.     // Class scoped types
  370.     //
  371.     typedef HBITMAP THandle;  // TBitmap encapsulates an HBITMAP
  372.  
  373.     // Constructors
  374.     //
  375.     TBitmap(HBITMAP handle, TAutoDelete autoDelete = NoAutoDelete);
  376.     TBitmap(const TClipboard& clipboard);
  377.     TBitmap(const TBitmap& bitmap);
  378.  
  379.     TBitmap(int width, int height, uint8 planes=1, uint8 bitCount=1, const void far* bits=0);
  380.     TBitmap(const BITMAP far* bitmap);
  381.     TBitmap(const TDC& Dc, int width, int height, bool discardable = false);
  382.     TBitmap(const TDC& Dc, const TDib& dib, uint32 usage=CBM_INIT);
  383.  
  384.     TBitmap(const TMetaFilePict& metaFile, TPalette& palette, const TSize& size);
  385.     TBitmap(const TDib& dib, const TPalette* palette = 0);
  386.  
  387.     TBitmap(HINSTANCE, TResId);
  388.    ~TBitmap();
  389.  
  390.     // Type Accessor & Conversion Operator
  391.     //
  392.     HBITMAP  GetHandle() const;
  393.     operator HBITMAP() const;
  394.  
  395.     // Get/set GDI Object information
  396.     //
  397.     bool        GetObject(BITMAP far& bitmap) const;
  398.     int         Width() const;
  399.     int         Height() const;
  400.     TSize       Size() const;
  401.     int         Planes() const;
  402.     int         BitsPixel() const;
  403.     uint32      GetBitmapBits(uint32 count, void far* bits) const;
  404.     uint32      SetBitmapBits(uint32 count, const void far* bits);
  405.     bool        GetBitmapDimension(TSize& size) const;
  406.     bool        SetBitmapDimension(const TSize& size, TSize far* oldSize=0);
  407.  
  408.     // Put this bitmap onto the clipboard
  409.     //
  410.     void  ToClipboard(TClipboard& clipboard);
  411.  
  412.   protected:
  413.     TBitmap();
  414.  
  415.     // Create a bitmap & fill in it's Handle
  416.     //
  417.     void Create(const TDib& dib, const TPalette& palette);
  418.     void Create(const TBitmap& src);
  419.  
  420.   private:
  421.     TBitmap& operator =(const TBitmap&);
  422. };
  423.  
  424. //
  425. // class TRegion
  426. // ~~~~~ ~~~~~~~
  427. // GDI Region class. Can construct a region from various shapes
  428. //
  429. class _OWLCLASS TRegion : private TGdiBase {
  430.   public:
  431.     // Class scoped types
  432.     //
  433.     typedef HRGN THandle;  // TRegion encapsulates an HRGN
  434.  
  435.     // Constructors
  436.     //
  437.     TRegion();
  438.     TRegion(HRGN handle, TAutoDelete autoDelete = NoAutoDelete);
  439.     TRegion(const TRegion& region);
  440.     TRegion(const TRect& rect);
  441.     enum TEllipse {Ellipse};
  442.     TRegion(const TRect& e, TEllipse);
  443.     TRegion(const TRect& rect, const TSize& corner);
  444.     TRegion(const TPoint* points, int count, int fillMode);
  445.     TRegion(const TPoint* points, const int* polyCounts, int count,
  446.             int fillMode);
  447.    ~TRegion();
  448.  
  449.     // Other initialization
  450.     //
  451.     void        SetRectRgn(const TRect& rect);
  452.  
  453.     // Type Accessor & Conversion Operator
  454.     //
  455.     HRGN     GetHandle() const;
  456.     operator HRGN() const;
  457.  
  458.     // Test and information functions/operators
  459.     //
  460.     bool        operator ==(const TRegion& other) const;
  461.     bool        operator !=(const TRegion& other) const;
  462.     bool        Contains(const TPoint& point) const;
  463.     bool        Touches(const TRect& rect) const;
  464.     int         GetRgnBox(TRect& box) const;
  465.     TRect       GetRgnBox() const;
  466.  
  467.     // Assignment operators
  468.     //
  469.     TRegion&    operator =(const TRegion& source);
  470.     TRegion&    operator +=(const TSize& delta);
  471.     TRegion&    operator -=(const TSize& delta);
  472.     TRegion&    operator -=(const TRegion& source);
  473.     TRegion&    operator &=(const TRegion& source);
  474.     TRegion&    operator &=(const TRect& source);
  475.     TRegion&    operator |=(const TRegion& source);
  476.     TRegion&    operator |=(const TRect& source);
  477.     TRegion&    operator ^=(const TRegion& source);
  478.     TRegion&    operator ^=(const TRect& source);
  479.  
  480. #if defined(OWL2_COMPAT)
  481.   public:
  482.     typedef ::TXGdi TXGdi;  // Exceptions moved to global scope
  483. #endif
  484. };
  485.  
  486. //
  487. // class TIcon
  488. // ~~~~~ ~~~~~
  489. // GDI object Icon class.  Can construct an icon from a resource or
  490. // explicit info.  Overloads the destructor since it is not a regular GDI
  491. // object.
  492. //
  493. class _OWLCLASS TIcon : private TGdiBase {
  494.   public:
  495.     // Class scoped types
  496.     //
  497.     typedef HICON THandle;  // TIcon encapsulates an HICON
  498.  
  499.     // Constructors
  500.     //
  501.     TIcon(HICON handle, TAutoDelete autoDelete = NoAutoDelete);
  502.     TIcon(HINSTANCE, const TIcon& icon);
  503.     TIcon(HINSTANCE, TResId);
  504.     TIcon(HINSTANCE, const char far* filename, int index);
  505.     TIcon(HINSTANCE, const TSize& size, int planes, int bitsPixel,
  506.           const void far* andBits, const void far* xorBits);
  507. #if defined(BI_PLAT_WIN32)
  508.     TIcon(const void* resBits, uint32 resSize);
  509.     TIcon(const ICONINFO* iconInfo);
  510. #endif
  511.    ~TIcon();
  512.  
  513.     // Type Accessor & Conversion Operator
  514.     //
  515.     HICON    GetHandle() const;
  516.     operator HICON() const;
  517.  
  518.     bool     operator ==(const TIcon& other) const;
  519.  
  520. #if defined(BI_PLAT_WIN32)
  521.     bool     GetIconInfo(ICONINFO* iconInfo) const;
  522. #endif
  523.  
  524.   private:
  525.     TIcon(const TIcon&); // Protect against copying of icons
  526.     TIcon& operator =(const TIcon&);
  527.  
  528. #if defined(OWL2_COMPAT)
  529.   public:
  530.     typedef ::TXGdi TXGdi;  // Exceptions moved to global scope
  531. #endif
  532. };
  533.  
  534. //
  535. // class TCursor
  536. // ~~~~~ ~~~~~~~
  537. // GDI object Cursor class.  Can construct a cursor from a resource or
  538. // explicit info.  Overloads the destructor since it is not a regular GDI
  539. // object.
  540. //
  541. class _OWLCLASS TCursor : public TGdiBase {
  542.   public:
  543.     // Class scoped types
  544.     //
  545.     typedef HCURSOR THandle;  // TCursor encapsulates an HCURSOR
  546.  
  547.     // Constructors
  548.     //
  549.     TCursor(HCURSOR handle, TAutoDelete autoDelete = NoAutoDelete);
  550.     TCursor(HINSTANCE, const TCursor& cursor);
  551.     TCursor(HINSTANCE, TResId);
  552.     TCursor(HINSTANCE, const TPoint& hotSpot,
  553.             const TSize& size, void far* andBits, void far* xorBits);
  554. #if defined(BI_PLAT_WIN32)
  555.     TCursor(const void* resBits, uint32 resSize);
  556.     TCursor(const ICONINFO* iconInfo);
  557. #endif
  558.    ~TCursor();
  559.  
  560.     // Type Accessor & Conversion Operator
  561.     //
  562.     HCURSOR  GetHandle() const;
  563.     operator HCURSOR() const;
  564.  
  565.     bool     operator ==(const TCursor& other) const;
  566.  
  567. #if defined(BI_PLAT_WIN32)
  568.     bool     GetIconInfo(ICONINFO* iconInfo) const;
  569. #endif
  570.  
  571.   private:
  572.     TCursor(const TCursor&); // Protect against copying of cursors
  573.     TCursor& operator =(const TCursor&);
  574.  
  575. #if defined(OWL2_COMPAT)
  576.   public:
  577.     typedef ::TXGdi TXGdi;  // Exceptions moved to global scope
  578. #endif
  579. };
  580.  
  581. //
  582. // class TDib
  583. // ~~~~~ ~~~~
  584. // Pseudo-GDI object Device Independent Bitmap (DIB) class.  DIBs really have
  585. // no Window's handle, they are just a structure containing format and palette
  586. // information and a collection of bits (pixels).  This class provides a very
  587. // convenient way to work with DIBs like any other GDI object.
  588. // The memory for the DIB is in one GlobalAlloc'd chunk so it can be passed to
  589. // the Clipboard, OLE, etc.
  590. // Overloads the destructor since it is not a real GDI object.
  591. //
  592. // This is what is really inside a .BMP file, what is in bitmap resources, and
  593. // what is put on the clipboard as a DIB.
  594. //
  595. class _OWLCLASS TDib : private TGdiBase {
  596.   public:
  597.     // Class scoped types
  598.     //
  599.     typedef HANDLE THandle;  // TDib encapsulates an memory HANDLE w/ a DIB
  600.  
  601.     // Constructors and destructor
  602.     //
  603.     TDib(HGLOBAL handle, TAutoDelete autoDelete = NoAutoDelete);
  604.     TDib(const TClipboard& clipboard);
  605.     TDib(const TDib& src);
  606.  
  607.     TDib(int width, int height, uint32 nColors, uint16 mode=DIB_RGB_COLORS);
  608.     TDib(HINSTANCE module, TResId resid);
  609.     TDib(const char* name);
  610.     TDib(TFile& file, bool readFileHeader = true);
  611. #if !defined(BI_DATA_NEAR)
  612.     TDib(istream& is, bool readFileHeader = false);
  613. #endif
  614.     TDib(const TBitmap& bitmap, const TPalette* pal = 0);
  615.    ~TDib();
  616.  
  617.     // Comparison operator
  618.     //
  619.     bool     operator ==(const TDib& other) const;
  620.  
  621.     // Access to the internal structures of the dib
  622.     //
  623.     const BITMAPINFO far*      GetInfo() const;
  624.     BITMAPINFO far*            GetInfo();
  625.     const BITMAPINFOHEADER far*GetInfoHeader() const;
  626.     BITMAPINFOHEADER far*      GetInfoHeader();
  627.     const TRgbQuad far*        GetColors() const;
  628.     TRgbQuad far*              GetColors();
  629.     const uint16 far*          GetIndices() const;
  630.     uint16 far*                GetIndices();
  631.     const void HUGE*           GetBits() const;
  632.     void HUGE*                 GetBits();
  633.  
  634.     // Type convert this dib by returning pointers to internal structures
  635.     //
  636.     HANDLE   GetHandle() const;
  637.     operator HANDLE() const;
  638.  
  639.     operator const BITMAPINFO far*() const;
  640.     operator BITMAPINFO far*();
  641.     operator const BITMAPINFOHEADER far*() const;
  642.     operator BITMAPINFOHEADER far*();
  643.     operator const TRgbQuad far*() const;
  644.     operator TRgbQuad far*();
  645.  
  646.     // Put this Dib onto the clipboard
  647.     //
  648.     void      ToClipboard(TClipboard& clipboard);
  649.  
  650.     // Get info about this Dib
  651.     //
  652.     bool      IsOK() const;         // Is DIB OK & info available
  653.     bool      IsPM() const;         // Is DIB stored in PM core format
  654.     int       Width() const;        // Width in pixels
  655.     int       Height() const;       // Height in pixels
  656.     int       FlippedY(int y) const;// Y flipped the other direction
  657.     TSize     Size() const;         // Width & Height in pixels
  658.     int       BitsPixel() const;    // Bits per pixel: 2, 4, 8, 16, 24, 32
  659.     int       Pitch() const;        // Width in bytes, or bytes per scan
  660.     uint32    Compression() const;  // Compression & encoding flags
  661.     uint32    SizeImage() const;    // Size of the DIB image bits in bytes
  662.  
  663.     long      NumColors() const;    // Number of colors in color table
  664.     uint      StartScan() const;    // Starting scan line
  665.     uint      NumScans() const;     // Number of scans
  666.     int32     SizeColors() const;   // Size of the color table in bytes.
  667.     uint32    SizeDib() const;      // Memory size of DIB in bytes
  668.     uint16    Usage() const;        // The mode or usage of the color table
  669.  
  670.     int       XOffset(uint16 x) const;
  671.     int       YOffset(uint16 y) const;
  672.  
  673.     void HUGE* PixelPtr(uint16 x, uint16 y);
  674.  
  675.     // Write this dib to a file by name, to file object or to an ostream
  676.     //
  677.     bool      WriteFile(const char* filename);
  678.     bool      Write(TFile& file, bool writeFileHeader = false);
  679. #if !defined(BI_DATA_NEAR)
  680.     bool      Write(ostream& os, bool writeFileHeader = false);
  681. #endif
  682.  
  683.     // Work with the color table in RGB mode
  684.     //
  685.     TColor    GetColor(int entry) const;
  686.     void      SetColor(int entry, const TColor& color);
  687.     int       FindColor(const TColor& color);
  688.     int       MapColor(const TColor& fromColor, const TColor& toColor, bool doAll = false);
  689.  
  690.     // Work with the color table in Palette relative mode
  691.     //
  692.     uint16    GetIndex(int entry) const;
  693.     void      SetIndex(int entry, uint16 index);
  694.     int       FindIndex(uint16 index);
  695.     int       MapIndex(uint16 fromIndex, uint16 toIndex, bool doAll = false);
  696.  
  697.     // Change from RGB to Palette, or from Palette to RGB color table mode
  698.     //
  699.     bool      ChangeModeToPal(const TPalette& pal);
  700.     bool      ChangeModeToRGB(const TPalette& pal);
  701.  
  702.     // Map colors in color table matching stock UI colors to current UI colors
  703.     //
  704.     enum {
  705.       MapFace      = 0x01,  // Or these together to control colors to map
  706.       MapText      = 0x02,  // to current SysColor values
  707.       MapShadow    = 0x04,
  708.       MapHighlight = 0x08,
  709.       MapFrame     = 0x10
  710.     };
  711.     void      MapUIColors(uint mapColors, const TColor* bkColor = 0);
  712.  
  713.     // Dib->Dib Blitting
  714.     //
  715.     void CopyBlt(int dstX, int dstY, TDib& srcDib, int width=0, int height=0);
  716.     void SpriteBlt(int dstX, int dstY, TDib& srcDib,
  717.                    int width=0, int height=0, uint8 transparentColor=0);
  718.     void MapToPalette(const TPalette& pal);
  719.  
  720.     // Internal DIB file Reda/Write functions talk to these interfaces
  721.     //
  722.     class _OWLCLASS IFileIn {
  723.       public:
  724.         virtual bool Read(void HUGE* buffer, long size) = 0;
  725.         virtual void Skip(long size) = 0;
  726.     };
  727.     class _OWLCLASS IFileOut {
  728.       public:
  729.         virtual bool Write(void HUGE* buffer, long size) = 0;
  730.     };
  731.  
  732.   protected:
  733.     TGdiBase::CheckValid;  // make this function available to derivatives
  734.     TGdiBase::Handle;      // and these members too
  735.     TGdiBase::ShouldDelete;
  736.  
  737.     // Protected ctor- derived classes need to fill in handle & get info
  738.     //
  739.     TDib();
  740.  
  741.     void      InfoFromHeader(const BITMAPINFOHEADER& infoHeader);
  742.     void      InfoFromHandle();  // Get info & members from handle
  743.     void      CopyOnWrite();     // Make sure we can write on info
  744. #if defined(BI_PLAT_WIN32)
  745.     void      ResToMemHandle();  // Perform RO res handle to mem handle copy
  746. #endif
  747.  
  748.     bool      ReadFile(const char* name);
  749.     bool      Read(TFile& file, bool readFileHeader = false);
  750. #if !defined(BI_DATA_NEAR)
  751.     bool      Read(istream& is, bool readFileHeader = false);
  752. #endif
  753.  
  754.     bool      LoadResource(HINSTANCE, TResId);
  755.  
  756.     bool      Read(IFileIn& in, bool readFileHeader = false);
  757.     bool      Write(IFileOut& out, bool writeFileHeader = false);
  758.  
  759.     static int ScanBytes(long w, int bpp); // Width+bpp to dword aligned bytes
  760.  
  761.     void MultiBlt(int type, int dstX, int dstY, TDib& srcDib,
  762.                   int width, int height, uint8 transparentColor=0);
  763.  
  764.   protected_data:
  765.     BITMAPINFO far* Info;       // Locked global alloc'd block, has sub ptrs:
  766.     uint32 far*     Mask;       //   Color mask[3] for 16 & 32 bpp bmps
  767.     TRgbQuad far*   Colors;     //   Color table[NumClrs] for any bmp
  768.     void HUGE*      Bits;       //   Pointer to bits (pixels)
  769.     long            NumClrs;    // Number of colors in color table
  770.     uint16          Mode;       // Palette or RGB based pixels
  771.     bool            IsResHandle;// Is Handle a resource handle (vs. Memory)
  772.  
  773.   private:
  774.     // Prevent accidental copying of object
  775.     //
  776.     TDib& operator =(const TDib&);
  777.  
  778. #if defined(OWL2_COMPAT)
  779.   public:
  780.     typedef ::TXGdi TXGdi;  // Exceptions moved to global scope
  781.     bool      LoadFile(const char* name);  // Old OWL 2.0 name
  782. #endif
  783. };
  784.  
  785. // Generic definitions/compiler options (eg. alignment) following the 
  786. // definition of classes
  787. #include <services/posclass.h>
  788.  
  789. #if defined(BI_NAMESPACE)
  790. } // namespace OWL
  791. #endif
  792.  
  793. //----------------------------------------------------------------------------
  794. // Inline implementations for abstract GDI object class and derived classes.
  795. //
  796.  
  797. #if !defined(OWL_DC_H)
  798. # include <owl/dc.h>
  799. #endif
  800. #if !defined(OWL_CLIPBOAR_H)
  801. # include <owl/clipboar.h>
  802. #endif
  803.  
  804. //
  805. // Get the palette object from the clipboard.
  806. //
  807. inline TClipboard& operator <<(TClipboard& clipboard, TPalette& palette)
  808. {
  809.   palette.ToClipboard(clipboard);
  810.   return clipboard;
  811. }
  812.  
  813. //
  814. // Get the bitmap object from the clipboard.
  815. //
  816. inline TClipboard& operator <<(TClipboard& clipboard, TBitmap& bitmap)
  817. {
  818.   bitmap.ToClipboard(clipboard);
  819.   return clipboard;
  820. }
  821.  
  822. //
  823. // Get the DIB from the clipboard.
  824. //
  825. inline TClipboard& operator <<(TClipboard& clipboard, TDib& dib)
  826. {
  827.   dib.ToClipboard(clipboard);
  828.   return clipboard;
  829. }
  830.  
  831. //
  832. // Return the handle of the GDI object.
  833. //
  834. inline HGDIOBJ TGdiObject::GetGdiHandle() const
  835. {
  836.   return HGDIOBJ(Handle);
  837. }
  838.  
  839. //
  840. // Return the handle of the GDI object.
  841. //
  842. inline TGdiObject::operator HGDIOBJ() const
  843. {
  844.   return GetGdiHandle();
  845. }
  846.  
  847. //
  848. // Returns true if the handles are equal.
  849. // This is a binary compare.
  850. //
  851. inline bool TGdiObject::operator ==(const TGdiObject& other) const
  852. {
  853.   return Handle == other.Handle;
  854. }
  855.  
  856. //
  857. // Retrieve the object's attributes into a buffer.
  858. //
  859. inline int TGdiObject::GetObject(int count, void far* object) const
  860. {
  861. #if defined(BI_PLAT_WIN32)
  862. # if defined(UNICODE)
  863.     return ::GetObjectW(Handle, count, object);
  864. #  else
  865.     return ::GetObjectA(Handle, count, object);
  866. #  endif
  867. #else
  868.   return ::GetObject(Handle, count, object);
  869. #endif
  870. }
  871.  
  872. #if defined(BI_PLAT_WIN32)
  873. //
  874. // Return the type of the GDI object.
  875. //
  876. inline uint32 TGdiObject::GetObjectType() const
  877. {
  878.   return ::GetObjectType(GetGdiHandle());
  879. }
  880. #endif
  881.  
  882. //
  883. // Returns true if this represents a real GDI object.
  884. //
  885. inline bool TGdiObject::IsGDIObject() const
  886. {
  887. #if defined(BI_PLAT_WIN16)
  888.   return ::IsGDIObject(GetGdiHandle()) != 0;
  889. #else
  890.   return GetObjectType() != 0;
  891. #endif
  892. }
  893.  
  894. //
  895. // Return the handle of the pen with type HPEN.
  896. //
  897. inline HPEN TPen::GetHandle() const
  898. {
  899.   return HPEN(GetGdiHandle());
  900. }
  901.  
  902. //
  903. // Return the handle of the pen with type HPEN.
  904. //
  905. inline TPen::operator HPEN() const
  906. {
  907.   return GetHandle();
  908. }
  909.  
  910. //
  911. // Retrieve the attributes for the pen.
  912. //
  913. inline bool TPen::GetObject(LOGPEN far& logPen) const
  914. {
  915.   return TGdiObject::GetObject(sizeof(logPen), &logPen) != 0;
  916. }
  917.  
  918. //
  919. // Return the handle of the brush with type HBRUSH.
  920. //
  921. inline HBRUSH TBrush::GetHandle() const
  922. {
  923.   return HBRUSH(GetGdiHandle());
  924. }
  925.  
  926. //
  927. // Return the handle of the brush with type HBRUSH.
  928. //
  929. inline TBrush::operator HBRUSH() const
  930. {
  931.   return GetHandle();
  932. }
  933.  
  934. //
  935. // Retrieve the attributes of the brush.
  936. //
  937. inline bool TBrush::GetObject(LOGBRUSH far& logBrush) const
  938. {
  939.   return TGdiObject::GetObject(sizeof(logBrush), &logBrush) != 0;
  940. }
  941.  
  942. #if defined(BI_PLAT_WIN16)
  943. //
  944. // Unrealize the object.
  945. //
  946. inline bool TBrush:: UnrealizeObject()
  947. {
  948.   return ::UnrealizeObject(GetHandle());
  949. }
  950. #endif
  951.  
  952. //
  953. // Return the handle of the font with type HFONT.
  954. //
  955. inline HFONT TFont::GetHandle() const
  956. {
  957.   return HFONT(GetGdiHandle());
  958. }
  959.  
  960. //
  961. // Return the handle of the font with type HFONT.
  962. //
  963. inline TFont::operator HFONT() const
  964. {
  965.   return GetHandle();
  966. }
  967.  
  968. //
  969. // Retrieve the attributes of the font.
  970. //
  971. inline bool TFont::GetObject(LOGFONT far& logFont) const
  972. {
  973.   return TGdiObject::GetObject(sizeof(logFont), &logFont) != 0;
  974. }
  975.  
  976. //
  977. // Return the height of the font.
  978. //
  979. inline int TFont::GetHeight() const
  980. {
  981.   return int(GetTextMetrics().tmHeight);
  982. }
  983.  
  984. //
  985. // Return the height of the font if selected into the DC.
  986. //
  987. inline int TFont::GetHeight(TDC& dc) const
  988. {
  989.   return int(GetTextMetrics(dc).tmHeight);
  990. }
  991.  
  992. //
  993. // Return the average width of the characters in the font.
  994. //
  995. inline int TFont::GetAveWidth() const
  996. {
  997.   return int(GetTextMetrics().tmAveCharWidth);
  998. }
  999.  
  1000. //
  1001. // Return the average width of the characters in the font if selected into
  1002. // the DC.
  1003. //
  1004. inline int TFont::GetAveWidth(TDC& dc) const
  1005. {
  1006.   return int(GetTextMetrics(dc).tmAveCharWidth);
  1007. }
  1008.  
  1009. //
  1010. // Return the maximum width of the characters in the font.
  1011. //
  1012. inline int TFont::GetMaxWidth() const
  1013. {
  1014.   return int(GetTextMetrics().tmMaxCharWidth);
  1015. }
  1016.  
  1017. //
  1018. // Return the maximum width of the characters in the font if selected into
  1019. // the DC.
  1020. //
  1021. inline int TFont::GetMaxWidth(TDC& dc) const
  1022. {
  1023.   return int(GetTextMetrics(dc).tmMaxCharWidth);
  1024. }
  1025.  
  1026. //
  1027. // Return the handle of the palette.
  1028. //
  1029. inline HPALETTE TPalette::GetHandle() const
  1030. {
  1031.   return HPALETTE(GetGdiHandle());
  1032. }
  1033.  
  1034. //
  1035. // Return the handle of the palette.
  1036. //
  1037. inline TPalette::operator HPALETTE() const
  1038. {
  1039.   return GetHandle();
  1040. }
  1041.  
  1042. //
  1043. // Unrealize the palette.
  1044. //
  1045. inline bool TPalette::UnrealizeObject()
  1046. {
  1047.   return ::UnrealizeObject(Handle);
  1048. }
  1049.  
  1050. //
  1051. // Resize the palette to numEntries.
  1052. //
  1053. inline bool TPalette::ResizePalette(uint numEntries)
  1054. {
  1055.   return ::ResizePalette(GetHandle(), numEntries);
  1056. }
  1057.  
  1058. //
  1059. // Animate palette from entry 'start' for 'count' entries.
  1060. //
  1061. inline void TPalette::AnimatePalette(uint start, uint count, const PALETTEENTRY far* entries)
  1062. {
  1063.   ::AnimatePalette(GetHandle(), start, count, entries);
  1064. }
  1065.  
  1066. //
  1067. // Change the palette entries.
  1068. //
  1069. inline uint TPalette::SetPaletteEntries(uint16 start, uint16 count, const PALETTEENTRY far* entries)
  1070. {
  1071.   return ::SetPaletteEntries(GetHandle(), start, count, entries);
  1072. }
  1073.  
  1074. //
  1075. // Change one palette entry.
  1076. //
  1077. inline uint TPalette::SetPaletteEntry(uint16 index, const PALETTEENTRY far& entry)
  1078. {
  1079.   return ::SetPaletteEntries(GetHandle(), index, 1, &entry);
  1080. }
  1081.  
  1082. //
  1083. // Retrieve the palette entries.
  1084. //
  1085. inline uint TPalette::GetPaletteEntries(uint16 start, uint16 count, PALETTEENTRY far* entries) const
  1086. {
  1087.   return ::GetPaletteEntries(GetHandle(), start, count, entries);
  1088. }
  1089.  
  1090. //
  1091. // Retrieve one palette entry.
  1092. //
  1093. inline uint TPalette::GetPaletteEntry(uint16 index, PALETTEENTRY far& entry) const
  1094. {
  1095.   return ::GetPaletteEntries(GetHandle(), index, 1, &entry);
  1096. }
  1097.  
  1098. //
  1099. // Retrieve the index of the palette entry that matches closest to the
  1100. // specified color.
  1101. //
  1102. inline uint TPalette::GetNearestPaletteIndex(const TColor& Color) const
  1103. {
  1104.   return ::GetNearestPaletteIndex(GetHandle(), Color);
  1105. }
  1106.  
  1107. //
  1108. // Retrieve the attributes of the palette object.
  1109. //
  1110. inline bool TPalette::GetObject(uint16 far& numEntries) const
  1111. {
  1112.   return TGdiObject::GetObject(sizeof(numEntries), &numEntries);
  1113. }
  1114.  
  1115. //
  1116. // Return the number of entries in the palette.
  1117. //
  1118. inline uint16 TPalette::GetNumEntries() const
  1119. {
  1120.   uint16 numEntries;
  1121.   if (TGdiObject::GetObject(sizeof(numEntries), &numEntries))
  1122.     return numEntries;
  1123.   return 0;
  1124. }
  1125.  
  1126. //
  1127. // Return the handle of the bitmap of type BITMAP.
  1128. //
  1129. inline HBITMAP TBitmap::GetHandle() const
  1130. {
  1131.   return HBITMAP(GetGdiHandle());
  1132. }
  1133.  
  1134. //
  1135. // Return the handle of the bitmap of type BITMAP.
  1136. //
  1137. inline TBitmap::operator HBITMAP() const
  1138. {
  1139.   return GetHandle();
  1140. }
  1141.  
  1142. //
  1143. // Retrieve the bits of the bitmap into the buffer.
  1144. //
  1145. inline uint32 TBitmap::GetBitmapBits(uint32 count, void far* bits) const
  1146. {
  1147.   return ::GetBitmapBits(GetHandle(), count, bits);
  1148. }
  1149.  
  1150. //
  1151. // Set the bits of the bitmap.
  1152. //
  1153. inline uint32 TBitmap::SetBitmapBits(uint32 count, const void far* bits)
  1154. {
  1155.   return ::SetBitmapBits(GetHandle(), count, bits);
  1156. }
  1157.  
  1158. //
  1159. // Retrieve the dimensions of the bitmap.
  1160. //
  1161. inline bool TBitmap::GetBitmapDimension(TSize& size) const
  1162. {
  1163.   return ::GetBitmapDimensionEx(GetHandle(), &size);
  1164. }
  1165.  
  1166. //
  1167. // Resize the bitmap.
  1168. //
  1169. inline bool TBitmap::SetBitmapDimension(const TSize& size, TSize far* oldSize)
  1170. {
  1171.   return ::SetBitmapDimensionEx(GetHandle(), size.cx, size.cy, oldSize);
  1172. }
  1173.  
  1174. //
  1175. // Retrieve the attributes of the bitmap.
  1176. //
  1177. inline bool TBitmap::GetObject(BITMAP far& Bitmap) const
  1178. {
  1179.   return TGdiObject::GetObject(sizeof(Bitmap), &Bitmap) != 0;
  1180. }
  1181.  
  1182. //
  1183. // Return the handle of the region with type HREGION.
  1184. //
  1185. inline HRGN TRegion::GetHandle() const
  1186. {
  1187.   return HRGN(Handle);
  1188. }
  1189.  
  1190. //
  1191. // Return the handle of the region with type HREGION.
  1192. //
  1193. inline TRegion::operator HRGN() const
  1194. {
  1195.   return GetHandle();
  1196. }
  1197.  
  1198. //
  1199. // Changes region into a rectangular region.
  1200. //
  1201. inline void TRegion::SetRectRgn(const TRect& rect)
  1202. {
  1203.   ::SetRectRgn(GetHandle(), rect.left, rect.top, rect.right, rect.bottom);
  1204. }
  1205.  
  1206. //
  1207. // Return true if the regions are identical (equal in size and shape).
  1208. //
  1209. inline bool TRegion::operator ==(const TRegion& other) const
  1210. {
  1211.   return ::EqualRgn(GetHandle(), other);
  1212. }
  1213.  
  1214. //
  1215. // Return the opposite of operator ==.
  1216. //
  1217. inline bool TRegion::operator !=(const TRegion& other) const
  1218. {
  1219.   return !::EqualRgn(GetHandle(), other);
  1220. }
  1221.  
  1222. //
  1223. // Return true if the point is within the region.
  1224. //
  1225. inline bool TRegion::Contains(const TPoint& point) const
  1226. {
  1227.   return ::PtInRegion(GetHandle(), point.x, point.y);
  1228. }
  1229.  
  1230. //
  1231. // Return true if any part of the rectangle is within the region.
  1232. //
  1233. inline bool TRegion::Touches(const TRect& rect) const
  1234. {
  1235.   return ::RectInRegion(GetHandle(), (TRect*)&rect); // API <const> typecast
  1236. }
  1237.  
  1238. //
  1239. // Return the bounding rectangle of the region.
  1240. //
  1241. inline int TRegion::GetRgnBox(TRect& box) const
  1242. {
  1243.   return ::GetRgnBox(GetHandle(), &box);
  1244. }
  1245.  
  1246. //
  1247. // Return the bounding rectangle of the region.
  1248. //
  1249. inline TRect TRegion::GetRgnBox() const
  1250. {
  1251.   TRect box;
  1252.   ::GetRgnBox(GetHandle(), &box);
  1253.   return box;
  1254. }
  1255.  
  1256. //
  1257. // Makes this region the same as the passed-in region.
  1258. //
  1259. inline TRegion& TRegion::operator =(const TRegion& source)
  1260. {
  1261.   ::CombineRgn(GetHandle(), source, 0, RGN_COPY);
  1262.   return *this;
  1263. }
  1264.  
  1265. //
  1266. // Moves the region by delta.
  1267. //
  1268. inline TRegion& TRegion::operator +=(const TSize& delta)
  1269. {
  1270.   ::OffsetRgn(GetHandle(), delta.cx, delta.cy);
  1271.   return *this;
  1272. }
  1273.  
  1274. //
  1275. // Moves the region negatively by delta.
  1276. //
  1277. inline TRegion& TRegion::operator -=(const TSize& delta)
  1278. {
  1279.   ::OffsetRgn(GetHandle(), -delta.cx, -delta.cy);
  1280.   return *this;
  1281. }
  1282.  
  1283. //
  1284. // Return the subtraction of one region from another.
  1285. //
  1286. inline TRegion& TRegion::operator -=(const TRegion& source)
  1287. {
  1288.   ::CombineRgn(GetHandle(), GetHandle(), source, RGN_DIFF);
  1289.   return *this;
  1290. }
  1291.  
  1292. //
  1293. // Return the intersection of two regions.
  1294. //
  1295. inline TRegion& TRegion::operator &=(const TRegion& source)
  1296. {
  1297.   ::CombineRgn(GetHandle(), GetHandle(), source, RGN_AND);
  1298.   return *this;
  1299. }
  1300.  
  1301. //
  1302. // Return the union of two regions.
  1303. //
  1304. inline TRegion& TRegion::operator |=(const TRegion& source)
  1305. {
  1306.   ::CombineRgn(GetHandle(), GetHandle(), source, RGN_OR);
  1307.   return *this;
  1308. }
  1309.  
  1310. //
  1311. // Return the exclusive-or of two regions.
  1312. //
  1313. inline TRegion& TRegion::operator ^=(const TRegion& source)
  1314. {
  1315.   ::CombineRgn(GetHandle(), GetHandle(), source, RGN_XOR);
  1316.   return *this;
  1317. }
  1318.  
  1319. //
  1320. // Return the handle of the icon with type HICON.
  1321. //
  1322. inline HICON TIcon::GetHandle() const
  1323. {
  1324.   return HICON(Handle);
  1325. }
  1326.  
  1327. //
  1328. // Return the handle of the icon with type HICON.
  1329. //
  1330. inline TIcon::operator HICON() const
  1331. {
  1332.   return GetHandle();
  1333. }
  1334.  
  1335. //
  1336. // Return true if the handles of two icons are identical.
  1337. //
  1338. inline bool TIcon::operator ==(const TIcon& other) const
  1339. {
  1340.   return Handle == other.Handle;
  1341. }
  1342.  
  1343. #if defined(BI_PLAT_WIN32)
  1344. //
  1345. // Retrieve attributes about the icon.
  1346. //
  1347. inline bool TIcon::GetIconInfo(ICONINFO* IconInfo) const
  1348. {
  1349.   return ::GetIconInfo(GetHandle(), IconInfo);
  1350. }
  1351.  
  1352. //
  1353. // Retrieve attributes about the cursor.
  1354. //
  1355. inline bool TCursor::GetIconInfo(ICONINFO* IconInfo) const
  1356. {
  1357.   return ::GetIconInfo((HICON)GetHandle(), IconInfo);
  1358. }
  1359. #endif
  1360.  
  1361. //
  1362. // Return the handle of the cursor with type HCURSOR.
  1363. //
  1364. inline HCURSOR TCursor::GetHandle() const
  1365. {
  1366.   return HCURSOR(Handle);
  1367. }
  1368.  
  1369. //
  1370. // Return the handle of the cursor with type HCURSOR.
  1371. //
  1372. inline TCursor::operator HCURSOR() const
  1373. {
  1374.   return GetHandle();
  1375. }
  1376.  
  1377. //
  1378. // Return true if the two handles for the cursors are identical.
  1379. //
  1380. inline bool TCursor::operator ==(const TCursor& other) const
  1381. {
  1382.   return Handle == other.Handle;
  1383. }
  1384.  
  1385. //
  1386. // Return true if the two handles for the DIBs are identical.
  1387. //
  1388. inline bool TDib::operator ==(const TDib& other) const
  1389. {
  1390.   return Handle == other.Handle;
  1391. }
  1392.  
  1393. //
  1394. // Return the BITMAPINFO of the DIB.
  1395. //
  1396. inline const BITMAPINFO far* TDib::GetInfo() const
  1397. {
  1398.   return Info;
  1399. }
  1400.  
  1401. //
  1402. // Return the BITMAPINFO of the DIB.
  1403. //
  1404. inline BITMAPINFO far* TDib::GetInfo()
  1405. {
  1406.   return Info;
  1407. }
  1408.  
  1409. //
  1410. // Return the BITMAPINFOHEADER of the DIB.
  1411. //
  1412. inline const BITMAPINFOHEADER far* TDib::GetInfoHeader() const
  1413. {
  1414.   return &Info->bmiHeader;
  1415. }
  1416.  
  1417. //
  1418. // Return the BITMAPINFOHEADER of the DIB.
  1419. //
  1420. inline BITMAPINFOHEADER far* TDib::GetInfoHeader()
  1421. {
  1422.   return &Info->bmiHeader;
  1423. }
  1424.  
  1425. //
  1426. // Return the colors used by the DIB.
  1427. //
  1428. inline const TRgbQuad far* TDib::GetColors() const
  1429. {
  1430.   return Colors;
  1431. }
  1432.  
  1433. //
  1434. // Return the colors used by the DIB.
  1435. //
  1436. inline TRgbQuad far* TDib::GetColors()
  1437. {
  1438.   return Colors;
  1439. }
  1440.  
  1441. //
  1442. // Return the number of colors used by the DIB.
  1443. //
  1444. inline const uint16 far* TDib::GetIndices() const
  1445. {
  1446.   return (const uint16*)Colors;
  1447. }
  1448.  
  1449. //
  1450. // Return the number of colors used by the DIB.
  1451. //
  1452. inline uint16 far* TDib::GetIndices()
  1453. {
  1454.   return (uint16*)Colors;
  1455. }
  1456.  
  1457. //
  1458. // Retrieve the bits of the DIB.
  1459. //
  1460. inline const void HUGE* TDib::GetBits() const
  1461. {
  1462.   return Bits;
  1463. }
  1464.  
  1465. //
  1466. // Retrieve the bits of the DIB.
  1467. //
  1468. inline void HUGE* TDib::GetBits()
  1469. {
  1470.   return Bits;
  1471. }
  1472.  
  1473. //
  1474. // Return the handle of the DIB with type HANDLE.
  1475. //
  1476. inline HANDLE TDib::GetHandle() const
  1477. {
  1478.   return Handle;
  1479. }
  1480.  
  1481. //
  1482. // Return the handle of the DIB with type HANDLE.
  1483. //
  1484. inline TDib::operator HANDLE() const
  1485. {
  1486.   return GetHandle();
  1487. }
  1488.  
  1489. //
  1490. // Return the BITMAPINFO of the DIB.
  1491. //
  1492. inline TDib::operator const BITMAPINFO far*() const
  1493. {
  1494.   return GetInfo();
  1495. }
  1496.  
  1497. //
  1498. // Return the BITMAPINFO of the DIB.
  1499. //
  1500. inline TDib::operator BITMAPINFO far*()
  1501. {
  1502.   return GetInfo();
  1503. }
  1504.  
  1505. //
  1506. // Return the BITMAPINFOHEADER of the DIB.
  1507. //
  1508. inline TDib::operator const BITMAPINFOHEADER far*() const
  1509. {
  1510.   return GetInfoHeader();
  1511. }
  1512.  
  1513. //
  1514. // Return the BITMAPINFOHEADER of the DIB.
  1515. //
  1516. inline TDib::operator BITMAPINFOHEADER far*()
  1517. {
  1518.   return GetInfoHeader();
  1519. }
  1520.  
  1521. //
  1522. // Return the colors used by the DIB.
  1523. //
  1524. inline TDib::operator const TRgbQuad far*() const
  1525. {
  1526.   return GetColors();
  1527. }
  1528.  
  1529. //
  1530. // Return the colors used by the DIB.
  1531. //
  1532. inline TDib::operator TRgbQuad far*()
  1533. {
  1534.   return GetColors();
  1535. }
  1536.  
  1537. //
  1538. // Return true if the DIB is valid.
  1539. //
  1540. inline bool TDib::IsOK() const
  1541. {
  1542.   return Info != 0;
  1543. }
  1544.  
  1545. //
  1546. // Return false always since PM bitmaps are not supported.
  1547. //
  1548. inline bool TDib::IsPM() const
  1549. {
  1550.   return false;
  1551. }
  1552.  
  1553. //
  1554. // Return the width of the DIB.
  1555. //
  1556. inline int TDib::Width() const
  1557. {
  1558.   return (int)Info->bmiHeader.biWidth;
  1559. }
  1560.  
  1561. //
  1562. // Return the height of the DIB.
  1563. //
  1564. inline int TDib::Height() const
  1565. {
  1566.   return (int)Info->bmiHeader.biHeight;
  1567. }
  1568.  
  1569. //
  1570. // Return the coordinate of y if the direction of the y-axis were reversed.
  1571. //
  1572. inline int TDib::FlippedY(int y) const
  1573. {
  1574.   return int(Info->bmiHeader.biHeight - 1 - y);
  1575. }
  1576.  
  1577. //
  1578. // Return the dimension of the DIB.
  1579. //
  1580. inline TSize TDib::Size() const
  1581. {
  1582.   return TSize(Width(), Height());
  1583. }
  1584.  
  1585. //
  1586. // Return the number of bytes used to store a scanline for the DIB.
  1587. // Rounded up to the nearest 32-bit boundary.
  1588. //
  1589. inline int TDib::ScanBytes(long w, int bpp)
  1590. {
  1591.   return (int)(((w*bpp+31)&(~31))/8);
  1592. }
  1593.  
  1594. //
  1595. // Return the number of bits used to store a pixel for the DIB.
  1596. //
  1597. inline int TDib::BitsPixel() const
  1598. {
  1599.   return Info->bmiHeader.biBitCount;
  1600. }
  1601.  
  1602. //
  1603. // Size of scan in bytes =
  1604. //   Pixel Width * bits per pixel rounded up to a uint32 boundary
  1605. //
  1606. inline int TDib::Pitch() const
  1607. {
  1608.   return ScanBytes(Width(), BitsPixel());
  1609. }
  1610.  
  1611. //
  1612. // Return type of compression for bottom-up DIBs.
  1613. //
  1614. inline uint32 TDib::Compression() const
  1615. {
  1616.   return Info->bmiHeader.biCompression;
  1617. }
  1618.  
  1619. //
  1620. // Return number of bytes used to store the image.
  1621. //
  1622. inline uint32 TDib::SizeImage() const
  1623. {
  1624.   return Info->bmiHeader.biSizeImage;
  1625. }
  1626.  
  1627. //
  1628. // Return number of colors used by the DIB.
  1629. //
  1630. inline long TDib::NumColors() const
  1631. {
  1632.   return NumClrs;
  1633. }
  1634.  
  1635. //
  1636. // Return the starting scan line.
  1637. // Always 0 because all DIBs are normalized.
  1638. //
  1639. inline uint TDib::StartScan() const
  1640. {
  1641.   return 0;
  1642. }
  1643.  
  1644. //
  1645. // Return number of scan lines.
  1646. // Always same as height of the DIB.
  1647. //
  1648. inline uint TDib::NumScans() const
  1649. {
  1650.   return Height();
  1651. }
  1652.  
  1653. //
  1654. // Return number of colors times the size of each entry in the table,
  1655. // whether it is an RGB color table or palette index table.
  1656. //
  1657. inline int32 TDib::SizeColors() const
  1658. {
  1659.   return Mode == DIB_RGB_COLORS ?
  1660.            (long)NumColors() * sizeof(RGBQUAD) :  // RGB color table
  1661.            (long)NumColors() * sizeof(uint16);    // Palette index color table
  1662. }
  1663.  
  1664. //
  1665. // Size of dib is measured as the end of the bits minus the start of the block
  1666. //
  1667. inline uint32 TDib::SizeDib() const
  1668. {
  1669.   return ((char HUGE*)Bits + SizeImage()) - (char HUGE*)Info;
  1670. }
  1671.  
  1672. //
  1673. // Return whether the DIB has palette color entries or RGB color entries.
  1674. //
  1675. inline uint16 TDib::Usage() const
  1676. {
  1677.   return Mode;
  1678. }
  1679.  
  1680. //
  1681. // Return the byte offset from the start of the scan line to the xth pixel.
  1682. //
  1683. inline int TDib::XOffset(uint16 x) const
  1684. {
  1685.   return int((uint32)x * BitsPixel() / 8);
  1686. }
  1687.  
  1688. //
  1689. // Return the starting position of the scan line.
  1690. //
  1691. inline int TDib::YOffset(uint16 y) const
  1692. {
  1693.   return int((uint32)Pitch() * y);
  1694. }
  1695.  
  1696. //
  1697. // Return the byte of where the pixel is located.
  1698. //
  1699. inline void HUGE* TDib::PixelPtr(uint16 x, uint16 y)
  1700. {
  1701.   return (uint8 HUGE*)Bits + XOffset(x) + YOffset(y);
  1702. }
  1703.  
  1704. //
  1705. // Copy the DIB.
  1706. //
  1707. inline void TDib::CopyOnWrite()
  1708. {
  1709. #if defined(BI_PLAT_WIN32)
  1710.   if (IsResHandle)
  1711.     ResToMemHandle();
  1712. #endif
  1713. }
  1714.  
  1715. //
  1716. // Copy the DIB by copying the bits.
  1717. //
  1718. inline void TDib::CopyBlt(int dstX, int dstY, TDib& srcDib, int width, int height)
  1719. {
  1720.   MultiBlt(0, dstX, dstY, srcDib, width, height);
  1721. }
  1722.  
  1723. //
  1724. // Transparent bit the DIB.
  1725. //
  1726. inline void TDib::SpriteBlt(int dstX, int dstY, TDib& srcDib,
  1727.                       int width, int height, uint8 transparentColor)
  1728. {
  1729.   MultiBlt(1, dstX, dstY, srcDib, width, height, transparentColor);
  1730. }
  1731.  
  1732. #if defined(OWL2_COMPAT)
  1733. //
  1734. // Load the DIB from the external file
  1735. //
  1736. inline bool TDib::LoadFile(const char* name)
  1737. {
  1738.   return ReadFile(name);
  1739. }
  1740. #endif
  1741.  
  1742. //
  1743. // Old GDI Orphan control macros
  1744. //
  1745. #define OBJ_REF_ADD(handle,type) TGdiObject::RefAdd((handle), (type))
  1746. #define OBJ_REF_REMOVE(handle) TGdiObject::RefRemove(handle)
  1747. #define OBJ_REF_INC(handle) TGdiObject::RefInc(handle)
  1748. #define OBJ_REF_DEC(handle, wantDelete) TGdiObject::RefDec((handle),(wantDelete))
  1749. #define OBJ_REF_COUNT(handle) TGdiObject::RefCount(handle)
  1750.  
  1751. #endif  // OWL_GDIOBJEC_H
  1752.